<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Admin\BaseController;
use App\Models\AdminCardLog;
use App\Models\MemberCardLog;

/***
 * Class AdminController
 * @package App\Http\Controllers\Admin
 * 后台管理员
 */
class CardLogController extends BaseController
{

    public function __construct(AdminCardLog $adminCardLog, MemberCardLog $memberCardLog)
    {
        parent::__construct();
        $this->adminLog = $adminCardLog;
        $this->memberLog = $memberCardLog;
    }

    /***
     * 管理员日志列表
     */
    public function getAlist()
    {
        $keyword = request('keyword', '');
        $where = [];
        if ($keyword) {
            if (is_numeric($keyword)) {
                $where['id'] = $keyword;
            } else {
                $where['nickname'] = ['like', '%' . $keyword . '%'];
            }
        }

        $order['id'] = 'desc';
        $rows = $this->adminCardLog->getList($where, '*', $order, 5);
        if ($rows) {
            $rows = $rows->toArray();
            $rows['pageNoList'] = getPageNoList($rows['last_page'],request('page',1),10);
        }
        return view('admin.log.admin', compact('rows', 'keyword'));
    }

    public function getMlist()
    {
        $keyword = request('keyword', '');
        $where = [];
        if ($keyword) {
            if (is_numeric($keyword)) {
                $where['id'] = $keyword;
            } else {
                $where['nickname'] = ['like', '%' . $keyword . '%'];
            }
        }

        $order['id'] = 'desc';
        $rows = $this->adminCardLog->getList($where, '*', $order, 5);
        if ($rows) {
            $rows = $rows->toArray();
            $rows['pageNoList'] = getPageNoList($rows['last_page'],request('page',1),10);
        }
        return view('admin.log.member', compact('rows', 'keyword'));
    }


    /**
     * 更新用户状态
     */
    public function getChange()
    {
        $id = request('id');
        $status = request('status');
        $res = $this->model->up($id, ['status' => $status]);
        if ($res) {
            echo json_encode(['code' => 200, 'msg' => 'success']);
            exit;
        }
        echo json_encode(['code' => 500, 'msg' => 'fail']);
    }
}